//
//  NavigationController.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/1/29.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import UIKit
import SnapKit

class NavigationController: LSFNavigationController {
   
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setNavigationBarAppearance()
        setBarButtonItemAppearance()
    }
    
    func setNavigationBarAppearance() {
        let appearance = UINavigationBar.appearance()
        
        appearance.shadowImage = UIImage() //去掉当行底部阴影

        let font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.init(0.1))
        appearance.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white,
                                          NSAttributedStringKey.font:font]

        appearance.tintColor = UIColor.white
        appearance.barTintColor = k_themeColor
        appearance.isTranslucent = true
        
        
        
        guard let backgourndView = lsf_navigationBarBackgroundView() else {
            return
        }
        let back = UIView()
        back.backgroundColor = k_themeColor
        backgourndView.addSubview(back)
        back.snp.makeConstraints { (maker) in
            maker.edges.equalTo(UIEdgeInsetsMake(0, 0, 0, 0))
        }
    }
    
    
    
    func setBarButtonItemAppearance() {
        let appearance = UIBarButtonItem.appearance()
        
        let clearShadow = NSShadow.init()
        clearShadow.shadowColor = UIColor.clear
        clearShadow.shadowOffset = CGSize.zero
        
        let font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.init(0.1))
        
        let normalTitleColor = UIColor.white
        let highlightedTitleColor = UIColor.white
        appearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:normalTitleColor,
                                           NSAttributedStringKey.shadow: clearShadow,
                                           NSAttributedStringKey.font:font], for: .normal)
        
        appearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: highlightedTitleColor,
                                           NSAttributedStringKey.shadow: clearShadow,
                                           NSAttributedStringKey.font:font], for: .highlighted)
        
        appearance.tintColor = UIColor.white
        
        let backImage = UIImage.lsf_image(color: UIColor.clear, size: CGSize.init(width: 55, height: 20))
        appearance.setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default)
    }

}
